package com.lg.happyfarmer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lg.happyfarmer.R;
import com.lg.happyfarmer.bean.Bank;

import java.util.ArrayList;
import java.util.List;

import xtom.frame.image.load.XtomImageWorker;

/**
 * Created by Torres on 2018/5/7.
 */

public class FirstRecyclerAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private ArrayList<Bank> tts = new ArrayList<>();
    private XtomImageWorker imageWorker;
    private int TYPE_TOP = 1;//第一张
    private int TYPE_ELSE = 2;//其它布局
    private List<Integer> mHeights = new ArrayList<>();

    public FirstRecyclerAdapter(Context mContext, ArrayList<Bank> tts) {
        this.mContext = mContext;
        this.tts = tts;
    }

    public void resetData(ArrayList<Bank> tts) {
        this.tts.clear();
        this.tts = tts;
        notifyDataSetChanged();

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_TOP) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.listitem_first_vp, parent, false);
            RecycleViewHolder_First holder_first = new RecycleViewHolder_First(view);
            return holder_first;
        } else {
            View view = LayoutInflater.from(mContext).inflate(R.layout.recycle_otheritem, parent, false);
            RecyclerViewHolder holder = new RecyclerViewHolder(view);
            return holder;
        }


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position == 0) {
            initrefreshdata_first((RecycleViewHolder_First) holder);
        } else {
            initrefreshdata((RecyclerViewHolder) holder, position);
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_TOP;
        } else
            return TYPE_ELSE;
    }


    @Override
    public int getItemCount() {
        return tts.size();
    }

    public static class RecyclerViewHolder extends RecyclerView.ViewHolder {
        //        View vAll;
//        ImageView imgGood;
        TextView tv_number;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
//            vAll = itemView.findViewById(R.id.vAll);
//            imgGood= (ImageView) itemView.findViewById(R.id.imgGood);
//            tvTime= (TextView) itemView.findViewById(R.id.tvTime);
//            tvPmOrAm= (TextView) itemView.findViewById(R.id.tvPmOrAm);
            tv_number = (TextView) itemView.findViewById(R.id.tv_number);
//            tvName= (TextView) itemView.findViewById(R.id.tvName);
//            tvDate= (TextView) itemView.findViewById(R.id.tvDate);
        }
    }


    public static class RecycleViewHolder_First extends RecyclerView.ViewHolder {

        //        View vFirst;
//        TextView tvName,tvExcellent,tvTake;
//        RoundedImageView imgHead;
        public RecycleViewHolder_First(View itemView) {
            super(itemView);
//            vFirst = itemView.findViewById(R.id.vFirst);
//            tvName= (TextView) itemView.findViewById(R.id.tvName);
//            imgHead= (RoundedImageView) itemView.findViewById(R.id.imgHead);
//            tvExcellent= (TextView) itemView.findViewById(R.id.tvExcellent);
//            tvTake= (TextView) itemView.findViewById(R.id.tvTake);
        }
    }

    /**
     * 初始化第一个布局
     *
     * @param holder
     */
    private void initrefreshdata_first(RecycleViewHolder_First holder) {

    }

    /**
     * 初始化第二个布局
     *
     * @param h
     */
    private void initrefreshdata(RecyclerViewHolder h, int position) {

        if (position == 1) {
            h.tv_number.setBackgroundResource(R.mipmap.tag_2);
            h.tv_number.setText("2");
        } else if (position == 2) {
            h.tv_number.setBackgroundResource(R.mipmap.tag_3);
            h.tv_number.setText("3");
        } else {
            h.tv_number.setVisibility(View.INVISIBLE);
        }


    }
}
